<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
	<jsp:include page="/include.jsp"/>
	<script type="text/javascript">
	
	$(function(){
		//日期组件
		$('#estimateDate').my97({
			dateFmt:'yyyyMMdd',
			startDate:[{
				doubleCalendar:false,
				isShowWeek:false,
				isShowClear:false,
				readOnly:true
				 
			}]
		});
		
		//加载指标名称数据
		$('#kqiName').combogrid({   
			delay: 500,
			panelWidth:450,
			mode: 'remote',   
			url: '${pageContext.request.contextPath}/mininganalysis/dataImportAction!getAllKqiName.action',   
			idField: 'kqiname',    
			textField: 'kqiname',  
	        pagination : true,//是否分页  
	        rownumbers:true,//序号  
	        collapsible:false,//是否可折叠的  
	        fit: true,//自动大小  
	        fitColumns:true,
	        pageList:[10,20,30],//可以设置每页记录条数的列表  
	        method:'post', 
	        sortName:'createtime',
	        sortOrder:'desc',
			columns: [[   
			      {field:'kqiid',title:'指标ID',width:50,sortable:true,align:'center'},   
			      {field:'kqiname',title:'指标名称',width:85,align:'center'},
			      {field:'kqiversionnum',title:'版本号',width:30,align:'center'},
			      {field:'periodType',title:'周期类型',width:50,align:'center',formatter:function(value,rowData,rowIndex){
			    	  if(rowData.periodType==3){//日粒度
			    		  return '日';
			    	  }
			    	  if(rowData.periodType==2){//月粒度
			    		  return '月';
			    	  }
			    	  if(rowData.periodType==4){//时粒度
			    		  return '时';
			    	  }
			    	  
			      }} 
			]],
			onSelect:function(value,rowData){
			//	$('#dqm_kpidatasearch_table').datagrid('loadData', { total: 0, rows: [] }); //清空数据
// 				$("#dqm_kpidatasearch_tempkpiid").val(rowData.kqiid);
// 				$("#dqm_kpidatasearch_kqiversionnum").val(rowData.kqiversionnum);
				//设置周期类型
				if(rowData.periodType==3){//日
// 					  selected="day";
// 					  $("#dqm_kpidatasearch_select_dayormonth").val("日粒度");
// 					  $("#dqm_kpidatasearch_select_periodType").val("day");
// 					  ChangeDataSearchPeriodType(3);//初始化日期类型
						$('#estimateDate').my97({
							dateFmt:'yyyyMMdd',
							startDate:[{
								doubleCalendar:false,
								isShowWeek:false,
								isShowClear:false,
								readOnly:true
							}]
						});
						$('#estimateDate').val(getDateStr()); 
				}
				if(rowData.periodType==2){//月
					$('#estimateDate').my97({
						dateFmt:'yyyyMM',
						startDate:[{
							doubleCalendar:false,
							isShowWeek:false,
							isShowClear:false,
							readOnly:true
						}]
					});
					$('#estimateDate').val(getMonthStr());
				}
				if(rowData.periodType==4){//时
					$('#estimateDate').my97({
						dateFmt:'yyyyMMddHH',
						startDate:[{
							doubleCalendar:false,
							isShowWeek:false,
							isShowClear:false,
							readOnly:true
						}]
					});
					$('#estimateDate').val(getHourStr());
				}
// 				loadColumns();
			},
			toolbar:'#dqm_kpidatasearch_toolbal'
	   }); 
		
		
		//查询表格数据
		getDatagridByID();
	});
	 //格式化日期函数:月
	   function getMonthStr(){
	       var date=new Date();
	  		var y = date.getFullYear();
	  		var m= date.getMonth();
	  		return y+(m<10?('0'+m):m);
	    }
	   //格式化日期函数:时
	   function getHourStr() {
		    var dd = new Date();
		    var y = dd.getFullYear();
		    var m = dd.getMonth()+1;//获取当前月份的日期
		    if(m<=9){
		    	m="0"+m;
		    }
		    var h = dd.getHours();//获取当前小时
		    if(h<10){
		       h="0"+h;
		    }
		    var d = dd.getDate();
		    if(d<=9){
		    	d="0"+d;
		    }
		    return y+m+d+h;
	   }
	    
	  
	   //格式化日期函数:日
	   function getDateStr() {
		    var dd = new Date();
		    var y = dd.getFullYear();
		    var m = dd.getMonth()+1;//获取当前月份的日期
		    if(m<=9){
		    	m="0"+m;
		    }
		    var d = dd.getDate();
		    if(d<=9){
		    	d="0"+d;
		    }
		    return y+m+d;
	   }
	    
	 function querykpiName(){
			var kqiname=$('#dqm_kpidatasearch_combogrid_kpiname').val();	
			var query={kqiname:kqiname}; //把查询条件拼接成JSON
			var grid=$("#kqiName").combogrid('grid');
			$(grid).datagrid('options').queryParams=query; //把查询条件赋值给datagrid内部变量
			$(grid).datagrid('load');
	 }
	 
	 function resetQuery(){
			$('#dqm_kpidatasearch_combogrid_kpiname').val('');
	 }
	
	//查询数据方法
	function getDatagridByID()
	{
		$("#dataEstimateAdjustTab").datagrid({
			url : '${pageContext.request.contextPath}/mininganalysis/DataEstimateAdjustAction!getAllDataestimatecalAdjustByID.action',
			queryParams:serializeObject($('#search_form')),
			fit:true,
			title:'人工调整数据',
			fit:true,
			remoteSort:false,
			singleSelect:true,
			nowrap:true,
			fitColumns:true,
			pagination:true,
			pageList:[10,20,30],
			rownumbers:true,
			singleSelect:false,
			pagePosition:'bottom',
			sortName:'estimateDate',
			sortOrder:'desc',	
			autoRowHeight:true,
			rownumbers:false,
			striped:true,
			columns:[[  {field:'estimateResultId',title:'指标名称',width:60,align:'left',hidden:true},
			            {field:'kqiName',title:'指标名称',width:60,align:'center',formatter:function(value,rowData,rowIndex){
			            	if(rowData.kqiName!=undefined){
			            		  return '<div style="width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="'+rowData.kqiName+'">'+rowData.kqiName+'</div>';
			            		  }

								}},
			            {field:'estimateDate',title:'评估日期',width:50,align:'center'},			            
			            {field:'thresholdMax',title:'阀值上限',width:50,align:'right'},
			            {field:'thresholdMin',title:'阀值下限',width:50,align:'right'},
			            {field:'adjustthresholdMax',title:'人工调整阀值上限',width:50,align:'right'},
			            {field:'adjustthresholdMin',title:'人工调整阀值下限',width:50,align:'right'},
						{field:'dimInfo',title:'维度信息',width:80,align:'center',formatter:function(value,rowData,rowIndex){
			            	if(rowData.dimInfo!=undefined){
			            		  return '<div style="width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="'+rowData.dimInfo+'">'+rowData.dimInfo+'</div>';
			            		  }

								}},
						{field:'adjustTime',title:'调整时间',width:60,align:'center'},
						{field:'dsafd',title:'操作',width:40,align:'center',formatter:function(value,rowData,rowIndex){
							return '<span  style="cursor:pointer" onclick="adjustDataEstimate('+rowData.estimateResultId+')"><img  src="${pageContext.request.contextPath}/images/icons/modify_or_edit.png" title="调整" alt="调整"/>调整&nbsp;&nbsp;</span>';
							
						}}
						
					]],
			toolbar:'#estimate_toobar'
		});
	}
	
	//修改
	function adjustDataEstimate(estimateResultId){		
        var pars="estimateResultId="+estimateResultId;
        window.top.$('<div/>').dialog({
			href:'${pageContext.request.contextPath}/mininganalysis/DataEstimateAdjustAction!getDataEstimate.action?'+pars,
			top:($(window).height()-250)*0.5,
		    left:($(window).width()-300)*0.5,
			width:600,
			modal:true,
			title:'修改',
			buttons:[{
				text:'保 存',
				iconCls:'',
				handler:function(){
					var d=window.top.$(this).closest('.window-body');
					window.top.$('#dataEstimate_adjust_form').form('submit',{
						url:'${pageContext.request.contextPath}/mininganalysis/DataEstimateAdjustAction!adjustDataEstimate.action',
						data:pars,
						success:function(result){
							try {
								var r = $.parseJSON(result);
								$.messager.show({
									title : '提示',
									msg : r.returnMsg
								});
								if (r.returnFlag) {
									d.dialog('destroy');
									$('#search_form').form('clear');
									getDatagridByID();
								}
								
							} catch (e) {
								$.messager.alert('提示', result);
							}
							}
						});
					}
				}],
			onClose:function(){
				window.top.$(this).dialog('destroy');
			}
		});
        
	}
	
	//分页查询
	function doQuery()
	{
		var dataGridOptions=$('#dataEstimateAdjustTab').datagrid('options');
		dataGridOptions.queryParams=serializeObject($('#search_form'));
		$('#dataEstimateAdjustTab').datagrid(dataGridOptions);
		$('#dataEstimateAdjustTab').datagrid('load');
	}
    
    //重置方法
    function resetData(){
    	$('#kqiName').combogrid('clear');
    	$('#estimateDate').val(''); 
    }
	</script>
</head>

<body class="easyui-layout">
    <form id="search_form" method="post">
        <div data-options="region:'north'" style="height:80px;border-bottom:none;border-top:none;">
	    	<table border="0" cellpadding="0" cellspacing="0" height="100%"  width="100%" >
					<tr>
						<td style="width:10%;text-align:right;" nowrap="nowrap">
							<label for="reportnameQ">指标名称：</label>
						</td>
						<td style="width:15%;text-align:right;" nowrap="nowrap">
							<input name="kqiName" id="kqiName" class="easyui-validatebox" type="text"/> 
						</td>
						<td style="width:10%;text-align:right;" nowrap="nowrap">
							<label for="reportnameQ">评估日期：</label>
						</td>
						<td style="width:15%;text-align:right;" nowrap="nowrap">
							<input id="estimateDate" type="date" name="estimateDate" />
						</td>					
						<td colspan="2" style="width:25%;text-align:right;" nowrap="nowrap">	   
				    		<input type="button" onclick="doQuery()" value="查询" style="background-image: url('${pageContext.request.contextPath}/images/login/search.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;cursor:pointer"/>	
				    		<input type="button" onclick="resetData()" value="重置" style="background-image: url('${pageContext.request.contextPath}/images/login/reset.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;margin-right:35px;cursor:pointer"/>			
		    			</td>
		    			<td style="width:10%;text-align:right;" nowrap="nowrap">
						</td>
						<td style="width:15%;text-align:right;" nowrap="nowrap">
						</td>		
					</tr>
			</table>
	    </div>
	    <div data-options="region:'center'" style="">  
			<table id="dataEstimateAdjustTab"></table>	
			
	   </div>
    </form>
    
    <div id="dqm_kpidatasearch_toolbal" style="padding:5px;height:auto">   
	    <div>  
	               指标名称 : <input id="dqm_kpidatasearch_combogrid_kpiname" type="text" class="easyui-validatebox" name="kpiname" style="width:150px" >  
	        <input type="button" id="" onclick="querykpiName()" value="查 询" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/search.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;"/>	
			<input type="button" id="" onclick="resetQuery()" value="重 置" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/reset.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;margin-right:55px"/> 
	    </div>  
    </div>
</body>
</html>
